/**
* Copyright (c) 2022 - present TinyVue Authors.
* Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/

@import '../custom.less';
@import '../mixins/common.less';
@import './vars.less';

@form-item-prefix-cls: ~'@{css-prefix}form-item';
@input-prefix-cls: ~'@{css-prefix}input';
@input-group-prefix-cls: ~'@{css-prefix}input-group';
@textarea-prefix-cls: ~'@{css-prefix}textarea';
@button-prefix-cls: ~'@{css-prefix}button';
@numeric-prefix-cls: ~'@{css-prefix}numeric';
@date-editor-prefix-cls: ~'@{css-prefix}date-editor';
@tooltip-prefix-cls: ~'@{css-prefix}tooltip';
@switch-prefix-cls: ~'@{css-prefix}switch';
@range-editor-prefix-cls: ~'@{css-prefix}range-editor';
@select-prefix-cls: ~'@{css-prefix}select';
@rate-prefix-cls: ~'@{css-prefix}rate';

.size-height(@height, @line-height, @margin-bottom) {
  margin-bottom: @margin-bottom;

  .@{form-item-prefix-cls}__content {
    line-height: @line-height;

    .@{css-prefix}checkbox,
    .@{css-prefix}radio {
      line-height: @height;
    }
    .@{css-prefix}checkbox-group {
      min-height: @height;
    }
    .@{numeric-prefix-cls} {
      display: block;

      &__input-inner {
        height: @height;
      }
    }
  }

  .@{form-item-prefix-cls}__label {
    height: @line-height;
    line-height: @line-height;
  }
}

.@{form-item-prefix-cls} {
  .component-css-vars-form-item();

  font-family: var(--ti-common-font-family);
  margin-bottom: var(--ti-form-item-margin-bottom-default);
  .clearfix();

  .@{form-item-prefix-cls}__content-muti-children {
    width: 100%;
  }

  & & {
    margin-bottom: 0;
  }

  &--small &__error {
    padding-top: 2px;
  }

  &--mini &__error {
    padding-top: 1px;
  }

  &--medium {
    .size-height(
      var(--ti-form-item-medium-line-height),
      var(--ti-form-item-medium-line-height),
      var(--ti-form-item-margin-bottom-medium)
    );
  }

  &--small {
    .size-height(
      var(--ti-form-item-small-line-height),
      var(--ti-form-item-small-line-height),
      var(--ti-form-item-margin-bottom-small)
    );
  }

  &--mini {
    .size-height(
      var(--ti-form-item-mini-line-height),
      var(--ti-form-item-mini-line-height),
      var(--ti-form-item-margin-bottom-mini)
    );
  }

  &__label-wrap {
    float: left;

    .@{form-item-prefix-cls}__label {
      display: inline-block;
      float: none;
    }
  }

  &__label {
    text-align: right;
    vertical-align: middle;
    float: left;
    font-size: var(--ti-form-item-label-font-size);
    color: var(--ti-form-item-label-text-color);
    height: var(--ti-form-item-label-line-height);
    line-height: var(--ti-form-item-label-line-height);
    padding-right: 8px;
    box-sizing: border-box;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  &__content {
    position: relative;
    font-size: var(--ti-form-item-label-font-size);
    line-height: var(--ti-form-item-label-line-height);
    .clearfix();

    .@{input-prefix-cls} {
      display: inline-block;
      &.@{range-editor-prefix-cls}.@{input-prefix-cls}__inner {
        display: inline-flex;
      }

      &.@{input-group-prefix-cls} {
        display: inline-table;
      }
    }

    .@{rate-prefix-cls} {
      vertical-align: middle;
      &__text {
        line-height: 1.5;
      }
    }

    .@{input-group-prefix-cls} {
      vertical-align: top;
    }

    .@{button-prefix-cls} + .@{button-prefix-cls} {
      margin-left: 8px;
    }

    .@{css-prefix}checkbox,
    .@{css-prefix}radio {
      vertical-align: middle;
      line-height: 30px;
    }
    .@{css-prefix}checkbox-group {
      min-height: var(--ti-form-item-label-line-height);
    }

    .@{numeric-prefix-cls},
    .@{date-editor-prefix-cls}--daterange.@{input-prefix-cls},
    .@{date-editor-prefix-cls}--daterange.@{input-prefix-cls}__inner,
    .@{date-editor-prefix-cls}--timerange.@{input-prefix-cls},
    .@{date-editor-prefix-cls}--timerange.@{input-prefix-cls}__inner {
      width: 100%;
    }
  }

  &__error {
    color: var(--ti-form-item-error-text-color);
    font-size: var(--ti-form-item-error-font-size);
    line-height: 1;
    padding-top: 4px;
    position: absolute;
    top: 100%;
    left: 0;

    .validate-icon {
      fill: var(--ti-form-item-error-text-color);
      margin-right: 8px;
    }
    .@{form-item-prefix-cls}__validate-message {
      vertical-align: middle;
    }
  }

  &__error--inline {
    position: relative;
    top: auto;
    left: auto;
    display: inline-block;
    margin-left: var(--ti-form-item-error-inline-margin-left);
  }

  &__error--block {
    position: relative;
    top: auto;
    left: auto;
    display: flex;
    margin-left: 0;
    padding-top: var(--ti-form-item-error-block-padding-top);
  }

  &.is-required:not(.is-no-asterisk) {
    .@{form-item-prefix-cls}__label-wrap > .@{form-item-prefix-cls}__label:before,
    & > .@{form-item-prefix-cls}__label:before {
      display: var(--ti-form-item-error-star-display);
      content: '*';
      color: var(--ti-form-item-error-star-text-color);
      margin-right: 4px;
    }
  }

  &.is-error {
    .@{input-prefix-cls}__inner,
    .@{input-prefix-cls}__inner:focus,
    .@{textarea-prefix-cls},
    .@{textarea-prefix-cls}:focus,
    .@{textarea-prefix-cls}__inner,
    .@{textarea-prefix-cls}__inner:focus {
      border-color: var(--ti-form-item-error-border-color);
      background-color: var(--ti-form-item-error-bg-color);
      --ti-textarea-bg-color: var(--ti-form-item-error-bg-color);
    }

    .@{input-group-prefix-cls}__append,
    .@{input-group-prefix-cls}__prepend {
      .@{input-prefix-cls}__inner {
        border-color: transparent;
      }
    }

    .@{input-prefix-cls}__validateIcon {
      color: var(--ti-form-item-error-text-color);
    }

    .@{numeric-prefix-cls}__input-inner,
    .@{numeric-prefix-cls}__input-inner:focus {
      border-color: var(--ti-form-item-error-border-color);
      background-color: var(--ti-form-item-error-bg-color);
    }
  }

  &--feedback .@{input-prefix-cls}__validateIcon {
    display: inline-block;
  }

  .@{input-prefix-cls}__validateIcon {
    display: none;
  }
}
